;layui.define(function(e) {
    layui.use(['table','layer','form','laydate'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
        //展示已知数据
        table.render({
            elem: '#idTest'
            ,cols: [[ //标题栏
                {field: 'position', title: '职位'}
                ,{field: 'name', title: '姓名'}
                ,{field: 'sex', title: '性别', minWidth: 120}
                ,{field: 'telephone', title: '电话'}
                ,{field: 'age', title: '年龄'}
                ,{field: 'Education', title: '学历'}
                ,{field: 'major', title: '专业'}
                ,{field: 'workingYears', title: '工龄',minWidth: 160}
                ,{field: 'Entry date', title: '入职日期',minWidth: 160}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:188, align:'center', toolbar: '#barDemo'}
            ]]
            ,height: 'full-400'
            ,cellMinWidth: 120
            ,data: [{
                "position": "销售顾问"
                ,"name": "龚天否"
                ,"sex": "男"
                ,"telephone": "13897913622"
                ,"age": "23"
                ,"Education": "硕士"
                ,"major": "金融学"
                ,"workingYears": "3"
                ,"entryDate":"2018-10-25"
            }]
            ,page: true //是否显示分页
        });

        //监听新增按钮

        //监听表格复选框选择
        table.on('checkbox(listTable)', function(obj){
            console.log(obj)
        });
        
        //监听工具条
        table.on('tool(listTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'details'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '详情'
                    ,content: 'details.html'
                    ,area: ['500px', '500px']
                    ,maxmin: true
                });
                layer.full(index);
            } else if(obj.event === 'rejectDetails'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '详情'
                    ,content: 'rejectDetails.html'
                    ,area: ['500px', '500px']
                    ,maxmin: true
                });
                layer.full(index);
            }
            else if(obj.event === 'soldOutShlef'){
                
                layer.alert('<div class="layui-form-item layui-col-md12"><p class="layui-form-label alert-label">请选择接收数据的账号</p><select class="layui-select alert-select"><option>请选择</option></select></div>',{
                     //skin: 'layui-layer-molv'
                     closeBtn: 1    // 是否显示关闭按钮 
                     ,btn: ['确定','取消']
                     ,yes:function(){
                        //确定按钮事件处理
                        
                     }
                     ,btn2:function(){
                        //关闭弹窗
                        layer.close(index);
                      } 
                  });  
            } else if(obj.event === 'putOnShelf'){
                layui.alert("上架")
            }else if(obj.event === 'edit'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '编辑'
                    ,content: 'newedit _order.html'
                    ,area: ['500px', '500px']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                        var paramId=body.find("input[name='id']");
                        paramId.val(111);
                    }
                });
                layer.full(index);
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.layadmin-takerates .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
         
        //执行一个laydate实例
        laydate.render({
            elem: '#date'
        });

        form.render();

        //订单池：按钮“新建订单”
        $("#neweditOrder").click(function () {
            var index = layer.open({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '新建订单'
                ,content: 'newedit _order.html'
                ,area: ['500px', '500px']
                ,skin:'my_skin'
                ,maxmin: true
            });
            layer.full(index);
        });
        
    });

    
    
    //输出模块
    e("newEditorFile", {})
});